package com.example.community.service.impl;

import com.example.community.DTO.addComment;
import com.example.community.entity.comment;
import com.example.community.repository.commentMapper;
import com.example.community.service.commentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.List;
import java.util.UUID;

@Service
public class commentImpl implements commentService {
    
    @Autowired
    private com.example.community.repository.commentMapper commentMapper;
    @Override
    public List<comment> queryOneByArticleId(String article_id) {
        List<comment> comments = commentMapper.queryOneByArticleId(article_id);
        return comments;
    }

    @Override
    public String addOne(addComment addComment) {
        String commentId = UUID.randomUUID().toString();
        Timestamp currentTime = new Timestamp(System.currentTimeMillis());
        comment comment = new comment();
        comment.setId(commentId);
        comment.setUser_id(addComment.getUser_id());
        comment.setArticle_id(addComment.getArticle_id());
        comment.setName(addComment.getName());
        comment.setContent(addComment.getContent());
        comment.setTime(currentTime);
        commentMapper.addOne(comment);
        return commentId;
    }

    @Override
    public int deleteOne(String id) {
        return commentMapper.deleteOne(id);
    }

    @Override
    public int deleteArticleAllComment(String articleId) {
        return commentMapper.deleteArticleAllComment(articleId);
    }
}
